package com.cjh.springcloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;

/**
 * @Author cjh
 * @Date 2020/12/3 17:32
 * @Version 1.0
 * hystrix服务熔断提供者
 */
@EnableEurekaClient// 服务启动后自动注册到eureka
@SpringBootApplication
@EnableDiscoveryClient// 服务发现
@EnableHystrix// 开启熔断的支持
@MapperScan("com.cjh.springcloud.dao")
public class HystrixEmpProvider_8001 {
    public static void main(String[] args) {
        SpringApplication.run(HystrixEmpProvider_8001.class, args);
    }

    /**
     * 增加一个servlet
     * 配合Dashboard流监控使用
     * 使用步骤：启动eureka集群、dashboard监控、hystrix提供者9001：http://localhost:9001/hystrix/
     * @return
     */
    @Bean
    public ServletRegistrationBean a(){
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        registrationBean.addUrlMappings("/actuator/hystrix.stream");
        return registrationBean;
    }
}
